package client.common.result;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class Result<T> {
    private Integer code;
    /**
     * 结果状态 ,具体状态码参见枚举类ReturnCodeEnum.java
     */
    private String message;
    private T data;
    
    public static Result<String> failure(int status, String s) {
        
        Result<String> resultData = new Result<>();
        resultData.setCode(status);
        resultData.setMessage(s);
        return resultData;
    }
    
    public static Result success() {
        Result resultData = new Result();
        resultData.setCode(200);
        resultData.setMessage("success");
        return resultData;
    }
    
    public static Result success(Object data) {
        Result resultData = new Result();
        resultData.setCode(200);
        resultData.setMessage("success");
        resultData.setData(data);
        return resultData;
    }
    
    public static Result fail(String message, Integer code, Object data) {
        Result resultData = new Result();
        resultData.setData(data);
        resultData.setCode(code);
        resultData.setMessage(message);
        return resultData;
    }
    
    public static Result fail(String message) {
        return fail(message, 500, null);
    }
    
    public static Result fail(String message, Object data) {
        return fail(message, 500, data);
    }
    
    public boolean isSuccess() {
        
        return code == 200;
    }
    
    public int getTotal() {
        return 0;
    }
}
